(function(vc) {
    vc.extends({
        data: {
            storeOrderCartDetailInfo: {
                orderId: '',
                appId: '',
                appName: '',
                deduction: '',
                personName: '',
                stateName: '',
                profitSharing: '',
                payPrice: '',
                createTime: '',
                addressInfo: {
                    username: '',
                    tel: '',
                    address: ''
                },
                remark: '',
                storeOrderCarts: [],
                storeOrderCartFees: [],
                events: [],
                storeOrderDiscounts: [],
                ledgers: []
            }
        },
        _initMethod: function() {
            $that.storeOrderCartDetailInfo.orderId = vc.getParam('orderId');
            $that._loadStoreOrder();
            $that._listOrderCart();
            $that._listOrderAddress();
            $that._listOrderCartEvent();
            $that._listStoreOrderCartFees();
            $that._listOrderDiscount();
            $that._ledgers();
        },
        _initEvent: function() {},
        methods: {
            _loadStoreOrder: function() {
                let param = {
                    params: {
                        page: 1,
                        row: 1,
                        orderId: $that.storeOrderCartDetailInfo.orderId
                    }
                };
                //发送get请求
                vc.http.apiGet('/storeOrder.queryStoreOrder',
                    param,
                    function(json, res) {
                        let _storeOrderCartManageInfo = JSON.parse(json);
                        vc.copyObject(_storeOrderCartManageInfo.data[0], $that.storeOrderCartDetailInfo)
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listOrderCart: function() {
                let param = {
                    params: {
                        page: 1,
                        row: 100,
                        orderId: $that.storeOrderCartDetailInfo.orderId,
                        shopId:vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/storeOrder.queryStoreOrderCart',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        let _storeOrderCart = _json.data
                        _storeOrderCart.forEach(_orderCart => {
                            if (_orderCart.productSpecDetails) {
                                let _productSpecDetails = _orderCart.productSpecDetails;
                                let _specValue = '';
                                _productSpecDetails.forEach(detail => {
                                    _specValue += (detail.detailValue + "/");
                                });
                                _orderCart.specValue = _specValue;
                            }
                        })
                        $that.storeOrderCartDetailInfo.storeOrderCarts = _storeOrderCart;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listOrderAddress: function() {
                let param = {
                    params: {
                        page: 1,
                        row: 1,
                        orderId: $that.storeOrderCartDetailInfo.orderId,
                        shopId:vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/storeOrder.queryStoreOrderAddress',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        if (_json.data[0] && _json.data.length > 0) {
                            vc.copyObject(_json.data[0], $that.storeOrderCartDetailInfo.addressInfo);
                        }
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listOrderCartEvent: function() {
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        orderId: $that.storeOrderCartDetailInfo.orderId,
                        shopId:vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/storeOrder.queryOrderEvent',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.storeOrderCartDetailInfo.events = _json.data;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listOrderDiscount: function() {
                var param = {
                    params: {
                        page: 1,
                        row: 50,
                        shopId: vc.getCurrentCommunity().shopId,
                        orderId: $that.storeOrderCartDetailInfo.orderId
                    }
                };
                //发送get请求
                vc.http.apiGet('/storeOrderDiscount/queryStoreOrderDiscount',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.storeOrderCartDetailInfo.storeOrderDiscounts = _json.data;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _ledgers: function() {
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        shopId: vc.getCurrentCommunity().shopId,
                        orderId: $that.storeOrderCartDetailInfo.orderId
                    }
                };
                //发送get请求
                vc.http.apiGet('/storeOrderLedgerAcct.listStoreOrderLedgerAcct',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.storeOrderCartDetailInfo.ledgers = _json.data;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listStoreOrderCartFees: function() {
                var param = {
                    params: {
                        page: 1,
                        row: 50,
                        orderId: $that.storeOrderCartDetailInfo.orderId,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/storeOrder.queryStoreOrderCartFee',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.storeOrderCartDetailInfo.storeOrderCartFees = _json.data;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _goBack: function() {
                vc.goBack()
            },
            getFeeSpecName: function(_item) {
                if (_item.feeSpecCd == '1001') {
                    return '服务费';
                }

                if (_item.feeSpecCd == '2002') {
                    return '折扣金';
                }

                if (_item.feeSpecCd == '3003') {
                    return '商品金';
                }
                return '未知'
            },
            getFeeSaveTypeName: function(_item) {
                if (_item.saveType == '45') {
                    return '账户充值';
                }

                if (_item.saveType == '55') {
                    return '优惠券';
                }

                return '未知'
            }
        }
    });
})(window.vc);